package com.jike.noobmoney.mvp.view.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.TuosuInfo;
import com.jike.noobmoney.mvp.presenter.TaskPresenter;
import com.jike.noobmoney.net.IView;
import com.jike.noobmoney.util.AppUtils;
import com.jike.noobmoney.util.SPUtils;
import com.jike.noobmoney.util.ToastUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Create by xuke on 2018/11/10
 * 我的任务->投诉
 */
public class MyTousuActivity extends BaseActivity implements IView {
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.tv_info)
    TextView tvInfo;
    @BindView(R.id.tv_huifu)
    TextView tvHuifu;
    @BindView(R.id.ll_info)
    LinearLayout llInfo;
    @BindView(R.id.et_feedback)
    EditText etFeedback;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    private TaskPresenter taskPresenter;
    private String o_id;

    @Override
    protected int layoutResID() {
        return R.layout.activity_my_tousu;
    }

    @Override
    protected void initData() {
        tvTitle.setText("订单投诉");
        taskPresenter = new TaskPresenter(this);
        o_id = getIntent().getStringExtra("o_id");
        taskPresenter.appealinfo(o_id, "gettousuinfo");
    }


    @OnClick({R.id.iv_back, R.id.tv_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_submit:
                tousu();
                break;
        }
    }

    private void tousu() {
        if (AppUtils.isFastClick()) {
            ToastUtils.showShortToastSafe("操作有点频繁,稍后重试");
            return;
        }
        String userid = SPUtils.getInstance().getString(ConstantValue.SpType.userid);
        String toushu = etFeedback.getText().toString().trim();
        //taskPresenter.tousu(userid, o_id, toushu, "tousu");
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        if ("gettousuinfo".equals(actionType)) {
            List<TuosuInfo.AppealBean> appealBeanList = (List<TuosuInfo.AppealBean>) data;
            if (appealBeanList != null && appealBeanList.size() > 0) {
                llInfo.setVisibility(View.VISIBLE);
                TuosuInfo.AppealBean appealBean = appealBeanList.get(0);
                String text = appealBean.getText();
                String reply = appealBean.getReply();
                tvInfo.setText(text);
                tvHuifu.setText(reply);
            } else {
                llInfo.setVisibility(View.GONE);
            }
        }

        if ("tousu".equals(actionType)) {
            ToastUtils.showShortToastSafe("" + msg);
            finish();
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        ToastUtils.showShortToastSafe(msg);
    }

}
